import { readFileSync } from 'fs'
import * as yaml from 'js-yaml'
import { join } from 'path'
import * as _ from 'lodash'

const YAML_COMMON_CONFIG_FILENAME = 'config.yml'

const filePath = join(__dirname, '../config', YAML_COMMON_CONFIG_FILENAME)

const envPath = join(__dirname, '../config', `config.${process.env.NODE_ENV}.yml`)

const fileConfig = yaml.load(readFileSync(filePath, 'utf8')) as Record<string, any>
const envConfig = yaml.load(readFileSync(envPath, 'utf8')) as Record<string, any>

export default () => {
    return _.merge(fileConfig, envConfig)
}